﻿// -------------------------------------------------------------------------
//    @FileName         :    NFCityWorldObject.cpp
//    @Author           :    Gao.Yi
//    @Date             :    2025-09-17
//    @Email			:    445267987@qq.com
//    @Module           :    NFCityWorldObject
//    @Desc             :
//
// -------------------------------------------------------------------------

#include "NFCityWorldObject.h"

#include "proto_common_base.nanopb.h"

NFCityWorldObject::NFCityWorldObject()
{
    if (EN_OBJ_MODE_INIT == NFShmMgr::Instance()->GetCreateMode())
    {
        CreateInit();
    }
    else
    {
        ResumeInit();
    }
}

NFCityWorldObject::~NFCityWorldObject()
{
}

int NFCityWorldObject::CreateInit()
{
    m_iMapInstId = INVALID_ID; // map object id ( not global-id)
    m_iMapGridIdx = INVALID_ID; // grid index in map
    m_iMapGridId = INVALID_ID; //map grid id

    m_iMapDescID = INVALID_ID;
    m_iDirection = INVALID_ID;

    m_cObjectType = EN_CITY_WOT_NONE;
    return 0;
}

int NFCityWorldObject::ResumeInit()
{
    return 0;
}

int NFCityWorldObject::OnEnterMap(int iMapInstId, int iMapDescId)
{
    LOG_TRACE(GetGlobalId(), "WorldObject OnEnterMap mapInstId:{} mapDescId:{}", iMapInstId, iMapDescId);
    m_iMapInstId = iMapInstId;
    m_iMapDescID = iMapDescId;

    UpdateMapData(iMapDescId, m_position, m_iDirection);

    return 0;
}

int NFCityWorldObject::OnLeaveMap()
{
    LOG_TRACE(GetGlobalId(), "WorldObject OnLeaveMap mapInstId:{} mapDescId:{}", m_iMapInstId, m_iMapDescID);
    m_iMapGridIdx = INVALID_ID;
    m_iMapGridId = INVALID_ID;

    return 0;
}

int NFCityWorldObject::OnEnterGrid(int iMapGridIdx, int iMapGridId, const Proto_Vector3& oPos, int iDirection)
{
    LOG_TRACE(GetGlobalId(), "WorldObject OnEnterGrid mapInstId:{} mapDescId:{} mapGridIdx:{} mapGridID:{} pos:({},{},{}) dir:{}", m_iMapInstId, m_iMapDescID, iMapGridIdx, iMapGridId, oPos.x, oPos.y, oPos.z, iDirection);
    m_iMapGridIdx = iMapGridIdx;
    m_iMapGridId = iMapGridId;

    m_position = oPos;

    m_iDirection = iDirection;

    UpdateMapData(m_iMapDescID, m_position, m_iDirection);

    return 0;
}

int NFCityWorldObject::MovePos(const Proto_Vector3& oPos, int iDirection)
{
    LOG_TRACE(GetGlobalId(), "WorldObject MovePos mapInstId:{} mapDescId:{} mapGridIdx:{} mapGridID:{} src pos:({},{},{}) src dir:{} to dst pos({}, {}, {}) dst dir:{}", m_iMapInstId, m_iMapDescID, m_iMapGridIdx, m_iMapGridId, m_position.x, m_position.y, m_position.z, m_iDirection, oPos.x, oPos.y,
             oPos.z, iDirection);

    m_position = oPos;

    m_iDirection = iDirection;

    UpdateMapData(m_iMapDescID, m_position, m_iDirection);

    return 0;
}

int NFCityWorldObject::OnLeaveGrid()
{
    LOG_TRACE(GetGlobalId(), "WorldObject OnLeaveGrid mapInstId:{} mapDescId:{} mapGridIdx:{} mapGridID:{}", m_iMapInstId, m_iMapDescID, m_iMapGridIdx, m_iMapGridId);
    m_iMapGridIdx = INVALID_ID;
    m_iMapGridId = INVALID_ID;

    return 0;
}
